#include "lista.h"
#include <stdlib.h>
#include <stdio.h>

struct node
{
	alfa elem;
	list tl;
};

list
vacia (void)
{
return NULL;
}

list
cons(alfa e, list l)
{
	list res;
	res = (list) malloc (sizeof(struct node));
	if (res != NULL)
	{
		res->elem = e;
		res->tl = l;
	}
	else
		exit(EXIT_FAILURE);
return res;
}

Bool
esvacia(list l)
{
return (l==NULL);
}

alfa
head(list l)
{
	if (l==NULL)
	{
		printf("Error: head sobre [] no anda\n");
		exit(EXIT_FAILURE);
	}
	else
		return l->elem;
}

list
tail(list l)
{
	if (l==NULL)
	{
		printf("Error: tail sobre [] no anda\n");
		exit(EXIT_FAILURE);
	}
	else
		return l->tl;
}

list
destructor(list l)
{
	list aux;
	while (l!=NULL)
	{
		aux = l;
		l = l->tl;
		free(aux);
	}
return l;
}
